﻿using BW.MesProject.Public.Application;
using BW.MesProject.Public.Application.Dto.Input;
using BW.MesProject.Public.Application.Dto.Output;
using BW.MesProject.Public.Domain.RBAC;
using BW.MesProject.Public.ErrorCode;
using BW.MesProject.WareHouse.Domain;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace BW.MesProject.Public.Host.Controllers
{
    /// <summary>
    /// 用户管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IUserServices _userServices;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="userServices">用户仓储</param>
        public UserController(IUserServices userServices)
        {
            this._userServices = userServices;
        }

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<UserLoginOutput> UserLogin([FromBody]UserLoginInput input)
        {
            return _userServices.UserLogin(input);
        }


        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> AddUser(UserModel model)
        {
            return _userServices.AddUser(model);
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<EMPOut>> GetUserNew([FromQuery] QryInput qryInput)
        {
            return _userServices.GetUserNew(qryInput);
        }

        /// <summary>
        /// 获取人员信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<List<UserLoginOutput>> GetUser(string? UserName, int pagesize, int pageNum, string DepId)
        {
            return _userServices.GetUser(UserName, pagesize, pageNum, DepId);
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ApiResult<int> UpdatEMP(UserModel model)
        {
            return _userServices.UpdateUser(model);
        }

        /// <summary>
        /// 修改启用
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPut]
        public ApiResult<int> UpdateEnable(UserModel model)
        {
            return _userServices.UpdateEnable(model);
        }


        /// <summary>
        /// 软删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpDelete]
        public ApiResult<int> UpdateDelete(string Id)
        {
            return _userServices.UpdateDelete(Id);
        }

        /// <summary>
        /// 查询编码
        /// </summary>
        /// <param name="UserId"></param>
        /// <returns></returns>
        [HttpGet]
        public ApiResult<int> GetUserId(string UserId)
        {
            return _userServices.GetUserId(UserId);
        }
    }
}
